//https://leetcode.cn/problems/add-strings/

#include <vector>
#include <string>
#include <queue>

using namespace std;

class Solution {
public:
    string addStrings(string num1, string num2) {
        if (num1.empty() || num2.empty())
            return "";

        std::vector<int> A, B;//"123" "123"
        for (int i = num1.size() - 1; i >= 0; --i) {
            A.push_back(num1[i] - '0');
        }
        for (int i = num2.size() - 1; i >= 0; --i) {
            B.push_back(num2[i] - '0');
        }
        auto max_size = std::max(A.size(),B.size()) +1;
        std::vector<int> C(max_size,0);

        for(size_t i=0;i<max_size;++i){
            if(i<A.size()){
                C[i]+=A[i];
            }
            if(i<B.size()){
                C[i]+=B[i];
            }
        }
        int carry=0;
        for (int i = 0; i < C.size(); i++) {
            carry += C[i];
            C[i] = carry % 10;
            carry /= 10;
        }
        while (C.size() > 1 && C.back() == 0) {
            C.pop_back();
        }
        std::string res="";
        for(size_t i=0;i<C.size();++i){
            res=std::to_string(C[i]) + res;
        }
        return res;
    }
};